package cc.linker.steplink.crm.merchanth5.controller;


import cc.linker.steplink.crm.commons.domain.WxUser;
import cc.linker.steplink.crm.merchanth5.commons.RequestFilter;
import cc.linker.steplink.crm.merchanth5.pojo.H5SignPo;
import cc.linker.steplink.crm.merchanth5.pojo.coupon.CustomerCouponVo;
import cc.linker.steplink.crm.merchanth5.service.SignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/h5/sign")
public class H5SignController {

    @Autowired
    private SignService signService;
    @Autowired
    private RequestFilter requestFilter;


    /**
     * 获取签到配置
     *
     * @param request
     * @return
     */
    @GetMapping("/getinfo")
    public H5SignPo getSignInfo(HttpServletRequest request) {
        WxUser wxUser = requestFilter.getWxUser(request);
        H5SignPo h5SignPo = new H5SignPo();
        h5SignPo.setOrgId(wxUser.getOrgId());
        h5SignPo.setCustomerId(wxUser.getCustomerId());
        return signService.getSignInfo(h5SignPo);
    }

    /**
     * 设置已提醒
     * @param request
     */
    @PostMapping("/setremind")
    public void setRemind(HttpServletRequest request){
        WxUser wxUser = requestFilter.getWxUser(request);
        String orgId = wxUser.getOrgId();
        String customerId = wxUser.getCustomerId();
        signService.setRemind(orgId,customerId);
    }

    /**
     * 获取用户签到记录
     *
     * @param request
     * @return
     */
    @GetMapping("/getsignlog")
    public Map<String, Object> getSignLog(HttpServletRequest request) {
        WxUser wxUser = requestFilter.getWxUser(request);
        return signService.getSignLog(wxUser.getOrgId(), wxUser.getCustomerId());
    }

    /**
     * 签到动作
     *
     * @param request
     */
    @PostMapping("/dosign")
    public List<CustomerCouponVo> sign(HttpServletRequest request) {
        WxUser wxUser = requestFilter.getWxUser(request);
        return signService.doSign(wxUser.getCustomerId(), wxUser.getOrgId());
    }
}
